from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker


class BasicView:
    def __init__(self):
        self.session = self.db_connect('Code')

    def db_connect(self, db):
        my_connect = 'mysql+mysqldb://root:790729@localhost:3306/{}?charset-utf8'.format(db)
        # 创建一个引擎
        engine = create_engine(my_connect,
                               echo=True
                               )
        # 创建一个会话
        Session = sessionmaker(bind=engine)
        session = Session()

        return session
